import { Sequelize } from 'sequelize'
import dataBaseConfig from '../configs/dataBase'

// 方法 2: 分别传递参数 (sqlite)
const sequelize = new Sequelize({
    dialect: 'mysql',
    host: dataBaseConfig.host,
    port: dataBaseConfig.port,
    username: dataBaseConfig.username,
    password: dataBaseConfig.password,
    database: dataBaseConfig.database,
    dialectOptions: {
        charset: 'utf8mb4',
    },
})

const testAuthenticate = async () => {
    try {
        await sequelize.authenticate()
        console.log('Connection has been established successfully.')
    } catch (error) {
        console.error('Unable to connect to the database:', error)
    }
}

testAuthenticate()

export default sequelize
